package com.ruoyi.energy.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.utils.DateUtils;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.energy.domain.vo.TreeSelect;
import com.ruoyi.system.api.domain.SysDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.energy.mapper.NyTransformerAccountMapper;
import com.ruoyi.energy.domain.NyTransformerAccount;
import com.ruoyi.energy.service.INyTransformerAccountService;

/**
 * 变压器部件Service业务层处理
 *
 * @author cjie
 * @date 2021-09-26
 */
@Service
public class NyTransformerAccountServiceImpl implements INyTransformerAccountService {
    @Autowired
    private NyTransformerAccountMapper nyTransformerAccountMapper;

    /**
     * 查询变压器部件
     *
     * @param id 变压器部件ID
     * @return 变压器部件
     */
    @Override
    public NyTransformerAccount selectNyTransformerAccountById(Integer id) {
        return nyTransformerAccountMapper.selectNyTransformerAccountById(id);
    }

    /**
     * 查询变压器部件列表
     *
     * @param nyTransformerAccount 变压器部件
     * @return 变压器部件
     */
    @Override
    public List<NyTransformerAccount> selectNyTransformerAccountList(NyTransformerAccount nyTransformerAccount) {
        return nyTransformerAccountMapper.selectNyTransformerAccountList(nyTransformerAccount);
    }

    /**
     * 新增变压器部件
     *
     * @param nyTransformerAccount 变压器部件
     * @return 结果
     */
    @Override
    public int insertNyTransformerAccount(NyTransformerAccount nyTransformerAccount) {
//        nyTransformerAccount.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        nyTransformerAccount.setCreateTime(DateUtils.getNowDate());
        nyTransformerAccount.setCreateBy(SecurityUtils.getUsername());
        return nyTransformerAccountMapper.insertNyTransformerAccount(nyTransformerAccount);
    }

    /**
     * 修改变压器部件
     *
     * @param nyTransformerAccount 变压器部件
     * @return 结果
     */
    @Override
    public int updateNyTransformerAccount(NyTransformerAccount nyTransformerAccount) {
        nyTransformerAccount.setUpdateTime(DateUtils.getNowDate());
        nyTransformerAccount.setUpdateBy(SecurityUtils.getUsername());
        return nyTransformerAccountMapper.updateNyTransformerAccount(nyTransformerAccount);
    }

    /**
     * 批量删除变压器部件
     *
     * @param ids 需要删除的变压器部件ID
     * @return 结果
     */
    @Override
    public int deleteNyTransformerAccountByIds(Integer[] ids) {
        return nyTransformerAccountMapper.deleteNyTransformerAccountByIds(ids);
    }

    /**
     * 删除变压器部件信息
     *
     * @param id 变压器部件ID
     * @return 结果
     */
    @Override
    public int deleteNyTransformerAccountById(Integer id) {
        return nyTransformerAccountMapper.deleteNyTransformerAccountById(id);
    }

    @Override
    public List<TreeSelect> buildTransformerTreeSelect(List<NyTransformerAccount> list) {
//        List<SysDept> deptTrees = buildDeptTree(depts);
//        return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
        return null;
    }

    /**
     * 构建前端所需要树结构
     *
     * @param depts 部门列表
     * @return 树结构列表
     */

//    public List<SysDept> buildDeptTree(List<SysDept> depts)
//    {
//        List<SysDept> returnList = new ArrayList<SysDept>();
//        List<Long> tempList = new ArrayList<Long>();
//        for (SysDept dept : depts)
//        {
//            tempList.add(dept.getDeptId());
//        }
//        for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
//        {
//            SysDept dept = (SysDept) iterator.next();
//            // 如果是顶级节点, 遍历该父节点的所有子节点
//            if (!tempList.contains(dept.getParentId()))
//            {
//                recursionFn(depts, dept);
//                returnList.add(dept);
//            }
//        }
//        if (returnList.isEmpty())
//        {
//            returnList = depts;
//        }
//        return returnList;
//    }


}
